package com.ruoyi.web.controller.eduManage;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

import com.ruoyi.eduManage.domain.EduComment;
import com.ruoyi.eduManage.service.IEduCommentService;

/**
 * 评语管理Controller
 */
@RestController
@RequestMapping("/manage/comment")
public class EduCommentController extends BaseController {

    @Autowired
    private IEduCommentService eduCommentService;

    /** 列表查询 */
    @PreAuthorize("@ss.hasPermi('manage:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(EduComment eduComment) {
        startPage();
        List<EduComment> list = eduCommentService.selectEduCommentList(eduComment);
        return getDataTable(list);
    }

    /** 导出 */
    @PreAuthorize("@ss.hasPermi('manage:comment:export')")
    @Log(title = "评语管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduComment eduComment) {
        List<EduComment> list = eduCommentService.selectEduCommentList(eduComment);
        ExcelUtil<EduComment> util = new ExcelUtil<>(EduComment.class);
        util.exportExcel(response, list, "评语数据");
    }

    /** 详情 */
    @PreAuthorize("@ss.hasPermi('manage:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId) {
        return success(eduCommentService.selectEduCommentByCommentId(commentId));
    }

    /** 新增 */
    @PreAuthorize("@ss.hasPermi('manage:comment:add')")
    @Log(title = "评语管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EduComment eduComment) {
        return toAjax(eduCommentService.insertEduComment(eduComment));
    }

    /** 修改 */
    @PreAuthorize("@ss.hasPermi('manage:comment:edit')")
    @Log(title = "评语管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EduComment eduComment) {
        return toAjax(eduCommentService.updateEduComment(eduComment));
    }

    /** 删除 */
    @PreAuthorize("@ss.hasPermi('manage:comment:remove')")
    @Log(title = "评语管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable String[] commentIds) {
        return toAjax(eduCommentService.deleteEduCommentByCommentIds(commentIds));
    }
}